﻿
using System;

namespace eightnum
{
    /// <summary>
    /// 产生随机数的类
    /// </summary>
    public class Generation
    {
        private int[,] table;

        public int[,] Table 
        {
            get 
            {
                return table;
            }
            set
            {
                
                table = value;
 
            }
        }
        public Generation()
        { //产生的八数码表的构造函数
            table =new int[3,3];
            
        }
        public void GenRandom()
        {
            //产生一组随机的二进制数
            Random rd = new Random();
            byte[] keys=new byte[9];
            rd.NextBytes(keys);
            //产生一个数组里面有1~8的数字
            //利用一个
            int[] items = new int[9];
            for (int i = 0; i < 9; i++)
                items[i] = i;
            Array.Sort(keys, items);
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    table[i, j] = items[i*3+j];
        }

    }
}
